﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DemoTest.Bll.Handlers;
using Nido.Common.BackEnd;
using DemoTest.Bll.Models;

namespace DemoMvc4Application.Controllers
{
    public class StudentController : Controller
    {
        StudentHandler handlerStudent = new StudentHandler();
        //
        // GET: /Student/

        public ActionResult Index()
        {
           GenericResponse<IEnumerable<Student>> studentResponse = handlerStudent.GetAllGeneric();
           if (studentResponse.Successful)
           {
               List<Student> studentList = new List<Student>();
               if (studentResponse.Result != null)
                   studentList = studentResponse.Result.Take(10).ToList();
               return View(studentList);
           }
           return View();
        }

        //
        // GET: /Student/Details/5

        public ActionResult Details(int id)
        {
            GenericResponse<Student> studentResponse = handlerStudent.GetSingleGeneric(x=>x.StudentId == id);
            if (studentResponse.Successful)
            {
                return View(studentResponse.Result);
            }
            return View();
        }

        //
        // GET: /Student/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Student/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Student/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Student/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Student/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Student/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
